home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / n_b_v203.zip / ARRSUM_B.DMO < prev    next >
Text File  |  1996-07-04  |  5KB  |  74 lines

  1. $if 0
  2.     ┌──────────────────────────╖                        PowerBASIC v3.20
  3.  ┌──┤          DASoft          ╟──────────────────────┬──────────────────╖
  4.  │  ├──────────────────────────╢    Copyright 1995    │ DATE: 1995-10-01 ╟─╖
  5.  │  │ FILE NAME   ARRSUM_B.DMO ║          by          ╘════════════════─ ║ ║
  6.  │  │                          ║  Don Schullian, Jr.                     ║ ║
  7.  │  ╘══════════════════════════╝                                         ║ ║
  8.  │ A license is hereby granted to the holder to use this source code in  ║ ║
  9.  │ any program, commercial or otherwise,  without receiving the express  ║ ║
  10.  │ permission of the copyright holder and without paying any royalties,  ║ ║
  11.  │ as long as this code is not distributed in any compilable format.     ║ ║
  12.  │  IE: source code files, PowerBASIC Unit files, and printed listings   ║ ║
  13.  ╘═╤═════════════════════════════════════════════════════════════════════╝ ║
  14.    │                ....................................                   ║
  15.    ╘═══════════════════════════════════════════════════════════════════════╝
  16. $endif
  17.  
  18. '.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°
  19. ' ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° °
  20.  
  21. $INCLUDE "DAS-NB01.INC"
  22.  
  23. RANDOMIZE TIMER
  24. COLOR 7, 0
  25. CLS
  26. ? "┌──────────────────────────────────────────────────────────────────────────────
  27. ? "│ fArrSumB?? ( ANYnumber, Els2Count%, StopAtSum??, ElsCounted%, StepSize% )
  28. ? "├──────────────────────────────────────────────────────────────────────────────
  29. ? "│ fArrSumB can count the elements of an array or a type. There are some natural
  30. ? "│ restrictions to the total and number of elements counted, etc. but they are
  31. ? "│ sufficiently high to allow for it's use under most circumstances. If you
  32. ? "│ assign a value of ZERO to StopAtSum?? fArrSumB will total all the elements,
  33. ? "│ but if it's value is > ZERO then fArrSumB will stop counting at the element
  34. ? "│ that offers a total =< StopAtSum?? and will return the number of elements
  35. ? "│ counted in ElsCounted%. StepSize% controls the number of bytes `skipped`
  36. ? "│ between the counted elements. ie: a one dimension byte array requires a
  37. ? "│ step size of +/- 1 (1 byte) where a TYPE could be almost any number.
  38. ? "└──────────────────────────────────────────────────────────────────────────────
  39.  
  40.                                                        '┌────────────────────
  41. TYPE StockItemsTYPE                                    '│ a type of 37 bytes
  42.   StockNo  AS STRING * 14                              '│ per element
  43.   ItemName AS STRING * 20                              '│
  44.   BinNo    AS INTEGER                                  '│
  45.   InStock  AS BYTE                                     '│
  46. END TYPE                                               '│
  47.                                                        '│
  48. DIM tS(50) AS StockItemsTYPE                           '│ 50 working types
  49.                                                        '│
  50. FOR I% = 1 TO 50                                       '│ assign random vals
  51.   LSET tS(I%) = STRING$( 37, 0 )                       '│ to the .InStock
  52.   tS(I%).InStock = fRND%( 1, 20 )                      '│ count
  53. NEXT                                                   '│
  54.                                                        '│
  55. I%  =  50                                              '│ start at the end
  56. F?? =  80                                              '│ max # of items/bin
  57. S%  = -37                                              '│ stepsize (backwards)
  58. B%  =   1                                              '│ 1st bin number
  59. DO                                                     '│
  60.   T?? = fArrSumB??( tS(I%).InStock, I%, F??, C%, S% )  '│ T?? = actual total
  61.   PRINT USING "BIN_### HAS ## PIECES of";B%,T??;       '│
  62.   PRINT USING " STOCK ITEM_#s ## thru ##";(I%-C%+1),I% '│ C% = items counted
  63.   DECR I%, C%                                          '│
  64.   INCR B%                                              '│
  65. LOOP UNTIL I% = 0                                      '│
  66.                                                        '│
  67. PRINT                                                  '│ to get the ASCii
  68. S$ = "HELLO WORLD"                                     '│ values of a string
  69. DIM S_ptr AS STRING PTR                                '│ try this trick.
  70. S_ptr = STRPTR32( S$ )                                 '│
  71. A?? = fArrSumB??( BYVAL S_ptr, LEN(S$), 0, Rels%, 1 )  '│ works pretty good
  72. PRINT "THE ASCII VALUE OF THE 'HELLO WORLD' IS:"; A??  '│ too!
  73.                                                        '└────────────────────
  74.